package com.bootdo.reverseproxy.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.reverseproxy.domain.MaskFeatureDO;
import com.bootdo.reverseproxy.service.MaskFeatureService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2018-03-07 17:55:56
 */
 
@Controller
@RequestMapping("/reverseproxy/maskFeature")
public class MaskFeatureController {
	@Autowired
	private MaskFeatureService maskFeatureService;
	
	@GetMapping()
//	@RequiresPermissions("reverseproxy:maskFeature:maskFeature")
	String MaskFeature(){
	    return "reverseproxy/maskFeature/maskFeature";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("reverseproxy:maskFeature:maskFeature")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<MaskFeatureDO> maskFeatureList = maskFeatureService.list(query);
		int total = maskFeatureService.count(query);
		PageUtils pageUtils = new PageUtils(maskFeatureList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("reverseproxy:maskFeature:add")
	String add(){
	    return "reverseproxy/maskFeature/add";
	}

	@GetMapping("/edit/{maskFeatureId}")
	@RequiresPermissions("reverseproxy:maskFeature:edit")
	String edit(@PathVariable("maskFeatureId") Long maskFeatureId,Model model){
		MaskFeatureDO maskFeature = maskFeatureService.get(maskFeatureId);
		model.addAttribute("maskFeature", maskFeature);
	    return "reverseproxy/maskFeature/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("reverseproxy:maskFeature:add")
	public R save( MaskFeatureDO maskFeature){
		if(maskFeatureService.save(maskFeature)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("reverseproxy:maskFeature:edit")
	public R update( MaskFeatureDO maskFeature){
		maskFeatureService.update(maskFeature);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("reverseproxy:maskFeature:remove")
	public R remove( Long maskFeatureId){
		if(maskFeatureService.remove(maskFeatureId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("reverseproxy:maskFeature:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] maskFeatureIds){
		maskFeatureService.batchRemove(maskFeatureIds);
		return R.ok();
	}
	
}
